<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="js,网站随机背景,标签栏favicon," />





  <link rel="alternate" href="/atom.xml" title="OBKoro1's Blog" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.2" />






<meta name="description" content="写在前面：本文内容见标题，之前github个人主页每次看到地址栏旁边的小图标默认的样子，都觉得丑爆了，前几天终于抽空把这个改了，还有之前背景图片用了一个大壁纸的网址链接，每次读取背景的时候感觉要半天那么久，一直想着要弄个反应速度快的！然后我又找到一个好方法。 效果(文章最后有demo)： 地址栏的图标：问题描述很早之前就对别的网页有这种漂亮的小图标好喜欢，自己也决定弄一个怎样添加这样的图标呢，没有">
<meta name="keywords" content="js,网站随机背景,标签栏favicon">
<meta property="og:type" content="article">
<meta property="og:title" content="标签栏图标，随机背景图，压缩背景">
<meta property="og:url" content="http://yoursite.com/2017/10/11/标签栏图标，随机背景图，压缩背景/index.html">
<meta property="og:site_name" content="OBKoro1&#39;s Blog">
<meta property="og:description" content="写在前面：本文内容见标题，之前github个人主页每次看到地址栏旁边的小图标默认的样子，都觉得丑爆了，前几天终于抽空把这个改了，还有之前背景图片用了一个大壁纸的网址链接，每次读取背景的时候感觉要半天那么久，一直想着要弄个反应速度快的！然后我又找到一个好方法。 效果(文章最后有demo)： 地址栏的图标：问题描述很早之前就对别的网页有这种漂亮的小图标好喜欢，自己也决定弄一个怎样添加这样的图标呢，没有">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://raw.githubusercontent.com/OBKoro1/article-demo/master/blogImg/2017_04_17_back.png">
<meta property="og:image" content="https://raw.githubusercontent.com/OBKoro1/article-demo/master/blogImg/2017_04_17_site.png">
<meta property="og:image" content="https://raw.githubusercontent.com/OBKoro1/article-demo/master/blogImg/2017_04_17_siteback.png">
<meta property="og:image" content="https://github.com/OBKoro1/article-demo/blob/master/blogImg/2017_04_17_ying.png?raw=true">
<meta property="og:image" content="https://github.com/OBKoro1/article-demo/blob/master/blogImg/2017_04_17_yi.png?raw=true">
<meta property="og:image" content="https://github.com/OBKoro1/article-demo/blob/master/blogImg/2017_04_17_china.png?raw=true">
<meta property="og:image" content="https://github.com/OBKoro1/article-demo/blob/master/blogImg/2017_04_17_500.png?raw=true">
<meta property="og:updated_time" content="2019-06-15T06:19:47.659Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="标签栏图标，随机背景图，压缩背景">
<meta name="twitter:description" content="写在前面：本文内容见标题，之前github个人主页每次看到地址栏旁边的小图标默认的样子，都觉得丑爆了，前几天终于抽空把这个改了，还有之前背景图片用了一个大壁纸的网址链接，每次读取背景的时候感觉要半天那么久，一直想着要弄个反应速度快的！然后我又找到一个好方法。 效果(文章最后有demo)： 地址栏的图标：问题描述很早之前就对别的网页有这种漂亮的小图标好喜欢，自己也决定弄一个怎样添加这样的图标呢，没有">
<meta name="twitter:image" content="https://raw.githubusercontent.com/OBKoro1/article-demo/master/blogImg/2017_04_17_back.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/10/11/标签栏图标，随机背景图，压缩背景/"/>





  <title>标签栏图标，随机背景图，压缩背景 | OBKoro1's Blog</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?64d57d0b926bbd27431daa89d2e0a76b";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">OBKoro1's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-前端算法">
          <a href="/arithmetic/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br />
            
            前端算法
          </a>
        </li>
      
        
        <li class="menu-item menu-item-博客最新更新">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            博客最新更新
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/10/11/标签栏图标，随机背景图，压缩背景/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="OBKoro1">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/uploads/hand1.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="OBKoro1's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">标签栏图标，随机背景图，压缩背景</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-10-11T22:17:30+08:00">
                2017-10-11
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/js/" itemprop="url" rel="index">
                    <span itemprop="name">js</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2017/10/11/标签栏图标，随机背景图，压缩背景/" class="leancloud_visitors" data-flag-title="标签栏图标，随机背景图，压缩背景">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  0 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  1分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><strong>写在前面：</strong>本文内容见标题，之前github个人主页每次看到地址栏旁边的小图标默认的样子，都觉得丑爆了，前几天终于抽空把这个改了，还有之前背景图片用了一个大壁纸的网址链接，每次读取背景的时候感觉要半天那么久，一直想着要弄个反应速度快的！然后我又找到一个好方法。</p>
<h3 id="效果-文章最后有demo-："><a href="#效果-文章最后有demo-：" class="headerlink" title="效果(文章最后有demo)："></a>效果(文章最后有demo)：</h3><p><img src="https://raw.githubusercontent.com/OBKoro1/article-demo/master/blogImg/2017_04_17_back.png" alt="Paste_Image.png"></p>
<h2 id="地址栏的图标："><a href="#地址栏的图标：" class="headerlink" title="地址栏的图标："></a>地址栏的图标：</h2><h3 id="问题描述"><a href="#问题描述" class="headerlink" title="问题描述"></a>问题描述</h3><p>很早之前就对别的网页有这种漂亮的小图标好喜欢，自己也决定弄一个<br><img src="https://raw.githubusercontent.com/OBKoro1/article-demo/master/blogImg/2017_04_17_site.png" alt=""><br>怎样添加这样的图标呢，没有设置的话，<strong>默认是没有的</strong>。</p>
<p><img src="https://raw.githubusercontent.com/OBKoro1/article-demo/master/blogImg/2017_04_17_siteback.png" alt="Paste_Image.png"></p>
<h4 id="其实，这个是通过favicon-ico来控制的。"><a href="#其实，这个是通过favicon-ico来控制的。" class="headerlink" title="其实，这个是通过favicon.ico来控制的。"></a>其实，这个是通过favicon.ico来控制的。</h4><p><strong>favicon.ico图标</strong>（图片大小有限制，下面有在线转换的网址）是网站的缩略标志，可以显示在浏览器标签、地址栏左边和收藏夹，是展示网站个性的缩略logo标志，也可以说是网站头像，如果要让网站看起来更专业、更美、更有个性，favicon.ico是必不可少的。</p>
<p><strong>代码：</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;link rel=&quot;shortcut icon bookmark&quot; type=&quot;image/png&quot; href=&quot;compress-bg/ico4.ico&quot;&gt;</span><br></pre></td></tr></table></figure></p>
<p><strong>概念 ：</strong><br>rel：链接外部文件与此文件的关系。<br>bookmark – 书签<br>Shortcut  Icon– 小图片</p>
<p><strong>注意：</strong>这里的图片是要用专门格式的，这里是两个在线转换图片格式的网址：<br><a href="http://ico.storyren.com/" target="_blank" rel="noopener">http://ico.storyren.com/</a><br><a href="http://www.bitbug.net/" target="_blank" rel="noopener">http://www.bitbug.net/</a></p>
<p>这里有两篇关于rel属性的详细介绍写的很多，有兴趣深究的可以看一下：<br>1.<a href="http://www.jb51.net/web/25005.html" target="_blank" rel="noopener">http://www.jb51.net/web/25005.html</a><br>2.<a href="http://paranimage.com/link-rel-attribute/" target="_blank" rel="noopener">http://paranimage.com/link-rel-attribute/</a></p>
<h2 id="随机背景图"><a href="#随机背景图" class="headerlink" title="随机背景图"></a>随机背景图</h2><p>###问题描述：<br>在github搭建了一个个人网站，（<a href="http://www.jianshu.com/p/4b29b1fb060f" target="_blank" rel="noopener">搭建方法</a>）背景图片随机，载入速度过慢：之前我用的是这种方法<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">body&#123;background:url(&quot;https://unsplash.it/1600/900?random&quot;);&#125;</span><br></pre></td></tr></table></figure></p>
<p><strong>解读：</strong>这里是将背景图片跟一个<strong>高清壁纸</strong>的网址链接（这个<a href="http://www.jianshu.com/p/4b29b1fb060f" target="_blank" rel="noopener">高清图片</a>网站还是不错的，推荐一波），随机倒是随机了，但每次读取背景的时候感觉要半天那么久（因为是分辨率比较高），但是这跟我的需求不一样，没工夫等那么久,so,有了下面的方法。</p>
<p>在网上查了两种方法，<strong>方法一：</strong></p>
<p><img src="https://github.com/OBKoro1/article-demo/blob/master/blogImg/2017_04_17_ying.png?raw=true" alt="Paste_Image.png"></p>
<p>博文链接：<a href="http://blog.csdn.net/ldl_xz/article/details/51532558" target="_blank" rel="noopener">http://blog.csdn.net/ldl_xz/article/details/51532558</a></p>
<p><strong>方法二（我目前用的）：</strong><br><strong>原理</strong>就是通过js代码来动态的生成一个代表图片路径的 字符串 或者 html代码</p>
<p>在 <body></body> 标签中使用class: bg<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;body class=&quot;bg&quot;&gt;&lt;/body&gt;</span><br></pre></td></tr></table></figure></p>
<p>js代码：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">    &lt;script type=&quot;text/javascript&quot;&gt;//产生随机背景图片</span><br><span class="line">    var bodyBgs = [];//图片url的路径</span><br><span class="line">    for (var i = 1; i &lt; 62; i++) &#123;//注意图片数量</span><br><span class="line">        bodyBgs[i] = &quot;compress-bg/bg&quot;+i+&quot;.jpg&quot;;//动态改变i的数量，随机选择到图片</span><br><span class="line">    &#125;;</span><br><span class="line">    var randomBgIndex = Math.round( Math.random() * 61 );</span><br><span class="line">//随机获取字符串标识，注意图片数量(这里随机数包括0，图片要从bg0开始到bg(n)）</span><br><span class="line">    console.log(randomBgIndex);</span><br><span class="line">    document.write(&apos;&lt;style&gt;.bg&#123;width:100%;background:url(&apos;);</span><br><span class="line">    document.write(bodyBgs[randomBgIndex]);</span><br><span class="line">    document.write(&apos;);background-size: cover;&#125;&lt;/style&gt;&apos;);</span><br><span class="line">    //上面的三个字符串可以用“+”连接成一个字符串，这里因为位置原因我拆开写了。</span><br><span class="line">    &lt;/script&gt;</span><br></pre></td></tr></table></figure></p>
<p><strong>执行过程：</strong><br>1.通过循环生成一组<strong>图片路径</strong>的字符串。//重要的就是图片路径这块儿的理解。<br>2.通过产生随机数，随机得到某张图片的路径字符串。<br>3.动态生成包含 css代码 的 html代码 。<br>4.通过浏览器查看网页的显示情况。（文末有 ）</p>
<h2 id="注意事项："><a href="#注意事项：" class="headerlink" title="注意事项："></a>注意事项：</h2><p>1.图片路径不要错！！！<br>2.随机数是从0开始的，注意bg[n]，n是从0开始。<br>3.要想背景载入速度够快的话，最好<strong>压缩压缩压缩（说三遍）一下图片</strong></p>
<p>这里推荐一个<strong>在线压缩图片超好用的网站</strong><br><a href="https://tinypng.com/#" target="_blank" rel="noopener">https://tinypng.com/#</a></p>
<p>这是米国的网站，最好翻墙一下，不然会出现这种情况（也可以下载破解版的软件，搜索tinypng就可以）</p>
<p><img src="https://github.com/OBKoro1/article-demo/blob/master/blogImg/2017_04_17_yi.png?raw=true" alt="Paste_Image.png"></p>
<p>我翻译了一下页面</p>
<p><img src="https://github.com/OBKoro1/article-demo/blob/master/blogImg/2017_04_17_china.png?raw=true" alt=""></p>
<p>需要注册一下，然后一个月可以压缩500张，一般是够用的。</p>
<p><img src="https://github.com/OBKoro1/article-demo/blob/master/blogImg/2017_04_17_500.png?raw=true" alt="Paste_Image.png"></p>
<p>demo在最下面。</p>
<p>favicon.ico图标参考文章：<a href="http://blog.csdn.net/hsd2012/article/details/51782545" target="_blank" rel="noopener">http://blog.csdn.net/hsd2012/article/details/51782545</a><br>随机生成背景图参考网址：<a href="http://www.tuicool.com/articles/y2miAby" target="_blank" rel="noopener">http://www.tuicool.com/articles/y2miAby</a></p>
<p>2017.4.8，以上。</p>
<p><strong>最后又到了观众朋友们最喜欢的求赞求关注环节：</strong>希望看完的朋友点个喜欢，也可以关注一下我，现在这阶段基本上每个月都不会少于十五篇文章（看到干货我也会进行分享）。码字不易，感谢支持，感激不尽！<br><strong>ps</strong>：如果希望我写哪方面的文章可以在底下评论，或者是私信我，虽然写的不好，但我就当这是记录自己成长的一种方式咯。（前提是我会了，如果不会我也会记下来，等会了的时候再更出来。）<br><a href="http://www.jianshu.com/u/8d1dd8c80f06" target="_blank" rel="noopener">简书主页链接</a>，<strong><a href="http://blog.csdn.net/OBKoro1?skin=dark1" target="_blank" rel="noopener">csdn博客主页链接</a> <a href="https://github.com/OBKoro1" target="_blank" rel="noopener">github</a> ， <a href="https://juejin.im/user/58714f0eb123db4a2eb95372" target="_blank" rel="noopener">掘金个人主页</a></strong></p>
<h2 id="说好的demo-demo地址"><a href="#说好的demo-demo地址" class="headerlink" title="说好的demo,demo地址"></a>说好的demo,<a href="https://obkoro1.github.io/article-demo/" target="_blank" rel="noopener">demo地址</a></h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br></pre></td><td class="code"><pre><span class="line">&lt;!doctype html&gt;</span><br><span class="line"></span><br><span class="line">&lt;html&gt;</span><br><span class="line"></span><br><span class="line">&lt;head&gt;</span><br><span class="line"></span><br><span class="line">&lt;meta charset=&quot;utf-8&quot; name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes&quot;/&gt;</span><br><span class="line"></span><br><span class="line">&lt;link rel=&quot;icon shortcut bookmark&quot; type=&quot;image/png&quot; href=&quot;compress-bg/ico1.ico&quot;&gt;</span><br><span class="line"></span><br><span class="line">&lt;title&gt;简书demo&lt;/title&gt;</span><br><span class="line"></span><br><span class="line">&lt;base target=&quot;_blank&quot; /&gt;</span><br><span class="line"></span><br><span class="line">&lt;style type=&quot;text/css&quot;&gt;</span><br><span class="line"></span><br><span class="line">.bg&#123;</span><br><span class="line"></span><br><span class="line">margin: 0;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">.allBox&#123;</span><br><span class="line"></span><br><span class="line">width: 80%;</span><br><span class="line"></span><br><span class="line">margin: 0 auto;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">p&#123;</span><br><span class="line"></span><br><span class="line">display: inline-block!important;</span><br><span class="line"></span><br><span class="line">width: 50%;</span><br><span class="line"></span><br><span class="line">font-size: 2rem;</span><br><span class="line"></span><br><span class="line">float: left;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">a&#123;</span><br><span class="line"></span><br><span class="line">text-decoration: none;</span><br><span class="line"></span><br><span class="line">target= &quot;_Blank&quot;;</span><br><span class="line"></span><br><span class="line">color:#7e6b5a;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">h1&#123;</span><br><span class="line"></span><br><span class="line">color: #d1c0a5;</span><br><span class="line"></span><br><span class="line">text-align: center;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&lt;/style&gt;</span><br><span class="line"></span><br><span class="line">&lt;/head&gt;</span><br><span class="line"></span><br><span class="line">&lt;body class=&quot;bg&quot;&gt;</span><br><span class="line"></span><br><span class="line">&lt;div class=&quot;allBox&quot;&gt;</span><br><span class="line"></span><br><span class="line">&lt;h1&gt;这里是简书demo&lt;/h1&gt;</span><br><span class="line"></span><br><span class="line">&lt;p&gt;&lt;a href=&quot;js-time/time-countDown.html&quot;&gt;1.倒计时和获取时间的demo&lt;/a&gt;&lt;/p&gt;</span><br><span class="line"></span><br><span class="line">&lt;/div&gt;</span><br><span class="line"></span><br><span class="line">&lt;script type=&quot;text/javascript&quot;&gt;//产生随机背景图片</span><br><span class="line"></span><br><span class="line">var bodyBgs = [];</span><br><span class="line"></span><br><span class="line">for (var i = 1; i &lt; 62; i++) &#123;//注意图片数量</span><br><span class="line"></span><br><span class="line">bodyBgs[i] = &quot;compress-bg/bg&quot;+i+&quot;.jpg&quot;;</span><br><span class="line"></span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">var randomBgIndex = Math.round( Math.random() * 61 );//随机获取字符串标识，注意图片数量</span><br><span class="line"></span><br><span class="line">console.log(randomBgIndex);</span><br><span class="line"></span><br><span class="line">document.write(&apos;&lt;style&gt;.bg&#123;width:100%;background:url(&apos;);</span><br><span class="line"></span><br><span class="line">document.write(bodyBgs[randomBgIndex]);</span><br><span class="line"></span><br><span class="line">document.write(&apos;);background-size: cover;&#125;&lt;/style&gt;&apos;);</span><br><span class="line"></span><br><span class="line">//上面的三个字符串可以用“+”连接成一个字符串，这里因为位置原因我拆开写了。</span><br><span class="line"></span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br><span class="line">&lt;/body&gt;</span><br><span class="line"></span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>
      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>听说，打赏我的人最后都找到了真爱。</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/pay/weixin.jpg" alt="OBKoro1 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/pay/ali.jpg" alt="OBKoro1 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/js/" rel="tag"><i class="fa fa-tag"></i> js</a>
          
            <a href="/tags/网站随机背景/" rel="tag"><i class="fa fa-tag"></i> 网站随机背景</a>
          
            <a href="/tags/标签栏favicon/" rel="tag"><i class="fa fa-tag"></i> 标签栏favicon</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/10/11/解读viewport—网页自适应移动app神器/" rel="next" title="解读viewport—网页自适应移动app神器">
                <i class="fa fa-chevron-left"></i> 解读viewport—网页自适应移动app神器
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/10/11/前端-PS-切图方法，图文详细/" rel="prev" title="前端 PS 切图方法，图文详细">
                前端 PS 切图方法，图文详细 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          
            <img class="site-author-image" itemprop="image"
              src="/uploads/hand1.jpg"
              alt="OBKoro1" />
          
            <p class="site-author-name" itemprop="name">OBKoro1</p>
            <p class="site-description motion-element" itemprop="description">种一棵树最好的时间是十年前,其次是现在</p>
        </div>

        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
            
              <a href="/archives">
            
                <span class="site-state-item-count">105</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">20</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">74</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/OBKoro1" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>GitHub</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://juejin.im/user/58714f0eb123db4a2eb95372" target="_blank" title="掘金">
                  
                    <i class="fa fa-fw fa-globe"></i>掘金</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://obkoro1.com/web_accumulate/" target="_blank" title="前端积累">
                  
                    <i class="fa fa-fw fa-globe"></i>前端积累</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://segmentfault.com/u/obkoro1/articles" target="_blank" title="segmentfault">
                  
                    <i class="fa fa-fw fa-globe"></i>segmentfault</a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#效果-文章最后有demo-："><span class="nav-number">1.</span> <span class="nav-text">效果(文章最后有demo)：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#地址栏的图标："><span class="nav-number"></span> <span class="nav-text">地址栏的图标：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#问题描述"><span class="nav-number">1.</span> <span class="nav-text">问题描述</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#其实，这个是通过favicon-ico来控制的。"><span class="nav-number">1.1.</span> <span class="nav-text">其实，这个是通过favicon.ico来控制的。</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#随机背景图"><span class="nav-number"></span> <span class="nav-text">随机背景图</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#注意事项："><span class="nav-number"></span> <span class="nav-text">注意事项：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#说好的demo-demo地址"><span class="nav-number"></span> <span class="nav-text">说好的demo,demo地址</span></a></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2017 &mdash; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">OBKoro1</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">
      156.0k
    </span>
  
</div>




<div>
<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span class="site-uv"><i class="fa fa-user"></i> 访问用户： <span class="busuanzi-value" id="busuanzi_value_site_uv">21621</span> 人 </span>
<span class="site-pv"><i class="fa fa-eye"></i> 访问次数： <span class="busuanzi-value" id="busuanzi_value_site_pv">68503</span> 次</span>

</div>



        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.2"></script>



  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>


  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  








  



  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("9ANFp60h6oVyxIPGlau3NOA4-gzGzoHsz", "tMdNuKMbFtN4QsekeNVu83TV");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  

  

  

</body>
</html>

